<template>
    <div class="app-container">
      <div class="mapDiv" v-loading="mapLoading">
        <!-- <div v-if="layerSelectViable" class="liduJiBie">
          <el-select v-model="layerName" placeholder="请选择烈度图层" @change="chooseProvince" clearable value-key="geom">
            <el-option v-for="item in liduJiBieData" :key="item.geom" :label="item.intensity1" :value="item">
            </el-option>
          </el-select>
          <el-select v-if="layerTypeVisable" v-model="layerType" placeholder="请选择图层评估方式" @change="chooseProvince1" clearable value-key="geom">
            <el-option v-for="item in layerTypeListAll" :key="item.name" :label="item.name" :value="item">
            </el-option>
          </el-select>
        </div> -->
        <div class="liduJiBie">
          <el-radio-group v-model="createTaskType" class="ml-4" style="display:flow">
            <el-radio value label="1" size="large">按小组个数新建并分配任务</el-radio>
            <br/>
            <el-radio label="2" size="large">地图圈定区域新建任务</el-radio>
          </el-radio-group>
        </div>
        <!--地图-->
        <DesaIndexMap v-if="completeRefreshData==true"
                     @getMap="getMap"
                     @closePingGu="closePingGu"
                     @outAndInterRing="outAndInterRing"
                     @saveGeom="saveGeom"
                      :shpLegendList="shpLegendList"
                      :shpDataList="fastSeismicInfluenceList"
                      :taskDataList="allDataList"
                      :positonGeom="positonGeom"
                      :sampleDataList="allDataList2"
                      :drawGeom="drawGeom"
                      :geomList="geomList"
                      :layerTypeMap="layerTypeMap"
        ></DesaIndexMap>
        <!--工具条控件-->
        <ControlToolBar v-if="completeRefreshData==true"
                        :createDraew="createDraew" :newTaskBool="newTaskBool"
                        :map="map" :pageType="pageType" :mapDrawType="mapDrawType"
                        :districtTreeList="districtTreeList" :taskDataList="allDataList"
                        :shpDataList="fastSeismicInfluenceList"
                        :showFsiSelectBool="showFsiSelectBool" :clearSelectFeatureBool="clearSelectFeatureBool"
                        :outAndInterRingData="outAndInterRingData" :taskRegionResultNameCodeList="taskRegionResultNameCodeList"
                        @getAllDrawGeom="getAllDrawGeom" @seismicInfluenceSelect="seismicInfluenceSelect"
                        @createTaskArea="createTaskArea" @createSamplePoint="createSamplePoint"
                        @closeNewTask="closeNewTask"
                        @openLayerSelect="openLayerSelect" @queryTaskRegionNameCodeListByGeomText="queryTaskRegionNameCodeListByGeomText"
        ></ControlToolBar>
        <!--灾区范围图层图例-->
        <div class="new-legendDiv">
          <div style="text-align: center;">
            <span style="font-size: 14px;font-weight: bold;color: rgb(16, 124, 229);">图例</span>
          </div>
          <div style="text-align: center;height: 20px;">
            <span style="font-size: 14px;font-weight: bold;color: rgb(16, 124, 229);">灾区范围烈度</span>
          </div>
          <template v-for="item in shpLegendList">
            <div v-show="item.show">
              <div><div style="border-color:rgb(152,152,152);" :style="{'background-color': item.color}" class="new-legendDiv-polygon"></div></div>
              <span>{{ item.fullName }}</span>
            </div>
          </template>
        </div>

        <div class="currentEventDiv">
            <p class="title">当前地震事件:
                <span v-if="currentEvent">{{ currentEvent.eventName }}</span>
                <span v-else>请在地震事件管理中设置当前地震事件</span>
            </p>
            <div>
              <el-checkbox v-model="isTaskList" @click="clearPosition" label="任务列表" size="large" />
              <el-checkbox v-model="isSamplPointList" label="抽样点列表" size="large" />
            </div>
        </div>

        <!--快速生成地震影响场版本信息列表-->
        <el-dialog v-model="showFastSiVersionTableBool" title="快速影响场版本选择" width="900px" append-to-body @close="closeVersionSelectDialog">
          <div style="padding:10px;">
            <el-table v-loading="tableLoading" :data="fastSiVersionList" stripe>
              <el-table-column label="单选" width="55px">
                <template #default="scope">
                  <el-radio :label="scope.row.fvId" v-model="selectRadio"
                            @click.native.stop.prevent="getCurrentRow(scope.row)">&nbsp;</el-radio>
                </template>
              </el-table-column>
              <el-table-column label="地震影响场图编号" align="center" prop="versionCode" width="200" />
              <el-table-column label="长轴方向" align="center" prop="angle" width="100" />
              <el-table-column label="生成人" align="center" prop="createUserName" width="100" />
              <el-table-column label="生成时间" align="center" prop="createTime" width="100" />
              <el-table-column label="中心点经度" align="center" prop="longitude" width="100" />
              <el-table-column label="中心点纬度" align="center" prop="latitude" width="100" />
              <el-table-column label="震级" align="center" prop="earthquakeLevel" width="100" />
            </el-table>
            <pagination v-show="total3 > 0" :total="total3" v-model:page="queryParams3.page" v-model:limit="queryParams3.rows"
                        @pagination="getFastSiVersionList" />
          </div>
          <template #footer>
            <div class="dialog-footer">
              <el-button type="primary" @click="submitVersionSelect">确 定</el-button>
            </div>
          </template>
        </el-dialog>

        <!--<div>
            <b style="cursor: pointer;" @click="openTask">新建任务（划定评估子区）</b><br>
            <b style="cursor: pointer;" @click="openPoint">新建抽样点</b>
        </div>

        <div>
            <el-checkbox v-model="isTaskList" label="任务列表" size="large" />
            <el-checkbox v-model="isSamplPointList" label="抽样点列表" size="large" />
        </div>-->
        <!--抽样点列表-->
        <div v-if="isSamplPointList">
            <el-table v-loading="loading2" :data="dataList2" stripe>
                <el-table-column label="序号" align="center" width="55">
                    <template #default="scope">
                        <span>{{ (queryParams.page - 1) * queryParams.rows + scope.$index + 1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="抽样点编号" align="center" prop="samplingPointCode">
                    <template #default="scope">
                        <span style="color: #107ce1;cursor: pointer;" @click="handleDetail2(scope.row.id)">{{
                            scope.row.samplingPointCode
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="抽样点名称" align="center" prop="samplingPointName" />
                <el-table-column label="详细地址" align="center" prop="address" show-overflow-tooltip />
                <el-table-column label="经度" align="center" prop="longitude" />
                <el-table-column label="纬度" align="center" prop="latitude" />
                <!-- <el-table-column label="状态" align="center" prop="taskStatus">
                    <template #default="scope">
                        <span v-if="scope.row.taskStatus == '0'">未开始</span>
                        <span v-if="scope.row.taskStatus == '1'">进行中</span>
                        <span v-if="scope.row.taskStatus == '2'">已完成</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="创建人" align="center" prop="createUserName" />
                <el-table-column label="创建时间" align="center" prop="createTime" />
                <el-table-column label="操作" align="center">
                    <template #default="scope">
                        <el-button type="text" @click="handleEdit2(scope.row.id)">修改</el-button>
                        <el-button type="text" @click="handleDelete2(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total2 > 0" :total="total2" v-model:page="queryParams2.page" v-model:limit="queryParams2.rows"
                @pagination="getList2" />
        </div>
        <!--任务列表-->
        <div v-if="isTaskList">
            <el-table v-loading="loading" :data="dataList" stripe>
                <el-table-column label="序号" align="center" width="55">
                    <template #default="scope">
                        <span>{{ (queryParams.page - 1) * queryParams.rows + scope.$index + 1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="任务编号" align="center" prop="taskCode">
                    <template #default="scope">
                        <span style="color: #107ce1;cursor: pointer;" @click="handleDetailPosition(scope.row.xitmId)">{{
                            scope.row.taskCode
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="任务名称" align="center" prop="taskName" />
                <el-table-column label="承担小组" align="center" prop="groupName" show-overflow-tooltip />
                <el-table-column label="任务状态" align="center" prop="taskStatus">
                    <template #default="scope">
                        <span v-if="scope.row.taskStatus == '0'">未开始</span>
                        <span v-if="scope.row.taskStatus == '1'">进行中</span>
                        <span v-if="scope.row.taskStatus == '2'">已完成</span>
                    </template>
                </el-table-column>
                <el-table-column label="创建人" align="center" prop="createUserName" />
                <el-table-column label="创建时间" align="center" prop="createTime" />
                <el-table-column label="操作" align="center">
                    <template #default="scope">
                        <el-button type="text" @click="handleEdit(scope.row.xitmId)">修改</el-button>
                        <el-button type="text" @click="handleDelete(scope.row.xitmId)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" v-model:page="queryParams.page" v-model:limit="queryParams.rows"
                @pagination="getList" />
        </div>
        <!--新建任务|修改任务|查看任务-->
        <el-dialog :title="title" v-model="open" width="900px" append-to-body>
            <el-form ref="addRef" label-width="120px" :model="form" :rules="rules">
                <el-row style="margin: 20px 0;">
                    <el-col :span="12">
                        <el-form-item label="任务编号" prop="taskCode" required>
                            <el-input v-model="form.taskCode" placeholder="请输入任务编号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="任务名称" prop="taskName">
                            <el-input v-model="form.taskName" placeholder="请输入任务名称" :disabled="isView" clearable />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="12">
                        <el-form-item label="评估子区编号" prop="evaluationSubareaCode" required>
                            <el-input v-model="form.evaluationSubareaCode" placeholder="请输入评估子区编号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="评估子区名称" prop="evaluationSubareaName">
                            <el-input v-model="form.evaluationSubareaName" placeholder="请输入评估子区名称" :disabled="isView"
                                clearable />
                        </el-form-item>
                    </el-col> -->
                    <!-- <el-col :span="12">
                        <el-form-item label="评估子区类别" prop="evaluationSubareaType">
                            <el-select v-model="form.evaluationSubareaType" placeholder="请选择评估子区类别" :disabled="isView"
                                clearable>
                                <el-option
                                    v-for="item in [{ label: '城市评估区', value: '城市评估区' }, { label: '农村评估区', value: '农村评估区' }]"
                                    :key="item.value" :label="item.label" :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="24">
                        <el-form-item label="任务区域" prop="taskRange" required>
                            <el-input v-model="form.taskRange" placeholder="请输入任务区域" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="承担小组">
                            <el-input v-model="form.groupName" placeholder="请选择组长" :suffix-icon="MoreFilled" readonly :disabled="isView"
                                @click="selectGroup" />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="创建人" prop="createUserName" required>
                            <el-input v-model="form.createUserName" placeholder="请输入创建人" disabled />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="12">
                        <el-form-item label="创建人单位" prop="createUnit" required>
                            <el-input v-model="form.createUnit" placeholder="请输入创建人单位" disabled />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="12">
                        <el-form-item label="创建时间" prop="createTime" required>
                            <el-input v-model="form.createTime" placeholder="请输入创建时间" disabled />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="save" v-if="!isView">保 存</el-button>
                    <el-button @click="open = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>
        <!--新建抽样点|修改抽样点|查看-->
        <el-dialog :title="title2" v-model="open2" width="900px" append-to-body>
            <el-form ref="addRef2" label-width="120px" :model="form2" :rules="rules2">
                <el-row style="margin: 20px 0;">
                    <el-col :span="12">
                        <el-form-item label="抽样点编号" prop="samplingPointCode">
                            <el-input v-model="form2.samplingPointCode" placeholder="请输入抽样点编号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="抽样点名称" prop="samplingPointName">
                            <el-input v-model="form2.samplingPointName" placeholder="请输入抽样点名称" :disabled="isView2" clearable />
                        </el-form-item>
                    </el-col>
                    <!-- <el-col :span="24">
                        <el-form-item label="抽样点详细位置" prop="address">
                            <el-input v-model="form2.address" placeholder="请输入抽样点详细位置" disabled />
                        </el-form-item>
                    </el-col> -->
                    <el-col :span="12">
                        <el-form-item label="经度" prop="longitude">
                            <el-input v-model="form2.longitude" placeholder="请输入经度" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="纬度" prop="latitude">
                            <el-input v-model="form2.latitude" placeholder="请输入纬度" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="创建人" prop="createUserName" v-show="title2=='查看抽样点' || title2=='修改抽样点'">
                        <el-input v-model="form2.createUserName" placeholder="请输入创建人" disabled />
                      </el-form-item>
                    </el-col>
                    <el-col :span="12">
                      <el-form-item label="创建时间" prop="createTime" v-show="title2=='查看抽样点' || title2=='修改抽样点'">
                        <el-input v-model="form2.createTime" placeholder="请输入创建时间" disabled />
                      </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="save2" v-if="!isView2">保 存</el-button>
                    <el-button @click="open2 = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="调查组列表" v-if="open1" v-model="open1" width="900px" append-to-body>
            <p></p>
            <el-table :data="dataList1" ref="tableRef" stripe row-key="xitId" @selection-change="handleSelectionChange">
                <el-table-column type="selection" align="center" :reserve-selection="true" width="55" />
                <el-table-column label="序号" align="center" width="55">
                    <template #default="scope">
                        <span>{{ (queryParams1.page - 1) * queryParams1.rows + scope.$index + 1 }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="调查组编号" align="center" prop="teamCode" show-overflow-tooltip>
                    <template #default="scope">
                        <span style="color: #107ce1;cursor: pointer;" @click="detail1(scope.row.xitId)">{{
                            scope.row.teamCode
                        }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="调查组名称" align="center" prop="teamName" />
                <el-table-column label="组长" align="center" prop="leader" />
            </el-table>

            <pagination v-if="open1" v-show="total1 > 0" :total="total1" v-model:page="queryParams1.page"
                v-model:limit="queryParams1.rows" @pagination="getList1" />
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" :disabled="multiple" @click="queryGroup">确 定</el-button>
                    <el-button @click="open1 = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>

        <el-dialog title="查看调查组" v-model="openGroup" width="900px" append-to-body>
            <el-form ref="groupRef" label-width="120px" :model="formGroup">
                <el-row style="margin: 20px 0;">
                    <el-col :span="12">
                        <el-form-item label="调查组编号" prop="teamCode">
                            <el-input v-model="formGroup.teamCode" placeholder="请输入调查组编号" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="调查组名称" prop="teamName">
                            <el-input v-model="formGroup.teamName" placeholder="请输入调查组名称" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="组长" prop="leader">
                            <el-input v-model="formGroup.leader" placeholder="请选择组长" :suffix-icon="MoreFilled" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="组长联系方式" prop="leaderPhone" required>
                            <el-input v-model="formGroup.leaderPhone" placeholder="请输入组长联系方式" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="调查组描述" prop="creatcommentInfoUser">
                            <el-input v-model="formGroup.creatcommentInfoUser" type="textarea" maxlength="500"
                                show-word-limit :autosize="{ minRows: 5, maxRows: 5 }" placeholder="请输入调查组描述" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="创建人单位" prop="company" required>
                            <el-input v-model="formGroup.company" placeholder="请输入创建单位" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="创建人" prop="createUser" required>
                            <el-input v-model="formGroup.createUser" placeholder="请输入创建人" disabled />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="创建时间" prop="createTime" required>
                            <el-input v-model="formGroup.createTime" placeholder="请输入创建时间" disabled />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <el-tabs v-model="activeName" class="demo-tabs" type="card">
                <el-tab-pane label="组员" name="first">
                    <el-row :gutter="10" class="mb8">
                        <el-col :span="1.5">
                            <el-button type="primary" disabled>添加组员</el-button>
                        </el-col>
                    </el-row>
                    <el-table :data="formGroup.personnel" stripe>
                        <el-table-column label="序号" type="index" align="center" width="55" />
                        <el-table-column label="姓名" align="center" prop="personName" />
                        <el-table-column label="性别" align="center" prop="gender" />
                        <el-table-column label="手机号" align="center" prop="tel" />
                        <el-table-column label="单位" align="center" prop="unit" />
                    </el-table>
                </el-tab-pane>
                <el-tab-pane label="司机" name="second">
                    <el-row :gutter="10" class="mb8">
                        <el-col :span="1.5">
                            <el-button type="primary" disabled>添加司机</el-button>
                        </el-col>
                    </el-row>
                    <el-table :data="formGroup.driver" stripe>
                        <el-table-column label="序号" type="index" align="center" width="55" />
                        <el-table-column label="姓名" align="center" prop="personName" />
                        <el-table-column label="性别" align="center" prop="gender" />
                        <el-table-column label="手机号" align="center" prop="tel" />
                        <el-table-column label="单位" align="center" prop="unit" />
                    </el-table>
                </el-tab-pane>
            </el-tabs>
            <template #footer>
                <div class="dialog-footer">
                    <el-button @click="openGroup = false">取 消</el-button>
                </div>
            </template>
        </el-dialog>
        <el-dialog title="删除任务区域" v-model="deleteTask" width="900px" append-to-body>
          <el-table :data="taskTableData" @selection-change="handleSelectionChangeDelete" style="width: 100%">
            <el-table-column type="selection" width="55" />
            <el-table-column prop="taskName" label="任务名称" />
            <el-table-column prop="groupName" label="小组名称" />
            <el-table-column prop="createUserName" label="创建人" />
            <el-table-column prop="createTime" label="创建时间" />
          </el-table>
          <template #footer>
              <div class="dialog-footer">
                  <el-button type="primary" @click="deleteTaskList">确 定</el-button>
                  <el-button @click="deleteTask = false">取 消</el-button>
              </div>
          </template>
        </el-dialog>
      </div>
    </div>
</template>
  
<script setup name="taskManage">
//地图
import DesaIndexMap from '@/map/fieldWork/taskManage/indexMap.vue';
import ControlToolBar from '@/map/fieldWork/taskManage/controlToolBar/map.vue';
import { getInvTaskManageList } from '@/api/map/shpFile';
import useEventStore from "@/store/modules/event";
import { MoreFilled } from '@element-plus/icons-vue'
import { getTaskList,deleteByXsemId,findById,updatePolygon,deletePolygon,getPageTask,accTotheGroupSave,getAreaTree,getInvGroupListByXsemId,getAdministrativeDivisionByGeomText,getCode,getAllSamPoiDataList,savePolygon, getAllList1, getAllList2, getDetail1,getPointCreateInfo2,getDetail2,saveData2,updateData2,del2 } from "@/api/fieldWork/taskManage.js"
import { getFastSiVersionListByXsemId,getFastSeiInfAndVerListByFvId,getFastSiVersionByXsemId,countSurTaskManageByType,setUnselectFastSiVersionDeleteTaskByXsemId,setSelectFastSiVersion } from "@/api/fastDisasterAnalysis/fastSeismicInfluence/intensity";
import { ref } from 'vue';

const { proxy } = getCurrentInstance();
const allDataList = ref([]);//全部任务列表
const allDataList2 = ref([]);//全部抽样点列表
const dataList = ref([]);
const createTaskType = ref('1')
const dataList1 = ref([]);
const dataList2 = ref([]);
const loading = ref(false);
const loading2 = ref(false);
const multiple = ref(true);
const isTaskList = ref(false);
const isSamplPointList = ref(false);
const open = ref(false);
const open1 = ref(false);
const open2 = ref(false);
const deleteTask = ref(false)
const total = ref(0);
const total1 = ref(0);
const total2 = ref(0);
const title = ref('新建任务')
const title2 = ref('新建抽样点')
const openGroup = ref(false);
const groupName = ref(false);
const groupId = ref(false);
const activeName = ref('first');
const isView = ref(false);
const isView2 = ref(false);
const liduJiBieData = ref([])
const layerName = ref('')
const layerType = ref('')
const layerTypeVisable = ref(false)
const currentEvent = computed(() => useEventStore().currentEvent);
const data = reactive({
    queryParams: {
        page: 1,
        rows: 10,
    },
    queryParams1: {
        page: 1,
        rows: 10,
    },
    queryParams2: {
        page: 1,
        rows: 10,
    },
    queryParams3: {//快速影响场查询
      page: 1,
      rows: 10,
    },
    form: {},
    form2: {},
    formGroup: {},
    rules: {
        taskName: [{ required: true, message: "任务名称不能为空", trigger: "blur" }],
        evaluationSubareaName: [{ required: true, message: "评估子区名称不能为空", trigger: "blur" }],
        evaluationSubareaType: [{ required: true, message: "评估子区类别不能为空", trigger: "change" }],
        // groupName: [{ required: true, message: "承担小组不能为空", trigger: "blur" }],
        taskRange: [{ required: true, message: "任务区域不能为空", trigger: "change" }],
    },
    rules2: {
      samplingPointName: [{ required: true, message: "抽样点名称不能为空", trigger: "blur" }],
      // address: [{ required: true, message: "抽样点详细位置不能为空", trigger: "blur" }],
      longitude: [{ required: true, message: "经度不能为空", trigger: "change" }],
      latitude: [{ required: true, message: "纬度不能为空", trigger: "change" }],
    },
    shpLegendList:[
      {fullName:"Ⅴ（5度）",name:"Ⅴ",value:"5",color:"rgba(255,220,220,0.7)",show:false},
      {fullName:"Ⅵ（6度）",name:"Ⅵ",value:"6",color:"rgba(255,190,190,0.7)",show:false},
      {fullName:"Ⅶ（7度）",name:"Ⅶ",value:"7",color:"rgba(255,127,127,0.7)",show:false},
      {fullName:"Ⅷ（8度）",name:"Ⅷ",value:"8",color:"rgba(200,40,40,0.7)",show:false},
      {fullName:"Ⅸ（9度）",name:"Ⅸ",value:"9",color:"rgba(168,0,0,0.7)",show:false},
      {fullName:"Ⅹ（10度）",name:"Ⅹ",value:"10",color:"rgba(140,0,0,0.7)",show:false},
      {fullName:"Ⅺ（11度）",name:"Ⅺ",value:"11",color:"rgba(105,0,0,0.7)",show:false},
      {fullName:"Ⅻ（12度）",name:"Ⅻ",value:"12",color:"rgba(80,0,0,0.7)",show:false},
    ],//灾区范围图例列表
    taskDataForm:{//任务信息
      geom:"",//当前选择的任务空间数据
      xstmId:"",//当前选择的任务ID，ID为空则新建任务
    },
    sampleDataForm:{//抽样点信息
      id:"",//当前选择的抽样点ID，ID为空则新建抽样点
      longitude:"",//当前选择的抽样点经度
      latitude:"",//当前选择的抽样点纬度
      geom:"",//当前选择的抽样点空间数据
      xstmId:"",//当前选择的抽样点所在的任务ID
    }
})
const { queryParams, form, queryParams1, formGroup, rules, rules2, queryParams2,form2,shpLegendList,taskDataForm,sampleDataForm,queryParams3 } = toRefs(data)

function openPoint(){
    isView2.value = false;
    title2.value = '新建抽样点';
    getInfo2();
}
const drawGeom = ref('')
const layerTypeListAll = ref([])
function chooseProvince(value) {
  layerType.value = ''
  if(value == '') {
    layerTypeVisable.value = false
    layerName.value = ''
    drawGeom.value = ''
  }else{
    layerTypeVisable.value = true
    layerName.value = value.intensity1
    drawGeom.value = value
    let taskData = []
    for(let i = 0;i < dataList.value.length;i++) {
      if(dataList.value[i].siId == drawGeom.value.fsiId) {
        taskData.push(dataList.value[i].geom)
      }
    }
    if(taskData.length == 0) {
      if(drawGeom.value.geom && drawGeom.value.geom.indexOf('),(') != -1) {
        layerTypeListAll.value = [
          { name: '整图层'},
          { name: '4点分割'},
        ]
      }else{
        layerTypeListAll.value = [
          { name: '整图层'},
          { name: '2点分割',geom: ''},
        ]
      }
    }else{
      layerTypeListAll.value = [
        { name: '剩余图层',geom: taskData},
        { name: '2点分割',geom: taskData},
      ]
    }
  }
  layerTypeMap.value = { name: 'change'} 
}
const layerTypeMap = ref({})
function chooseProvince1(value) {
  if(value == '') {
    layerType.value = ''
    layerTypeMap.value = {name: ''}
  }else{
    layerType.value = value.name
    layerTypeMap.value = value
  }
}
const taskRegionResultNameCodeList = ref([])
function queryTaskRegionNameCodeListByGeomText(geomText) {
    getAdministrativeDivisionByGeomText({geomText: geomText}).then((response) => {
      nextTick(() => {
        taskRegionResultNameCodeList.value = response.data;
      });
    });
  }
function getInfo2() {
    getPointCreateInfo2({eventCode:currentEvent.value.eventCode}).then(res => {
        form2.value = {};//清空
        open2.value = true;
        proxy.resetForm("addRef2");
        form2.value.samplingPointCode = res.data;//编号
        //抽样点经纬度
        form2.value.longitude = sampleDataForm.value.longitude;
        form2.value.latitude = sampleDataForm.value.latitude;
        form2.value.geom = sampleDataForm.value.geom;
        form2.value.xitmId = sampleDataForm.value.xitmId;//任务id
        form2.value.xsemId = currentEvent.value.id;//地震事件id
        //根据经纬度获取地址
        getLonLatAddress(sampleDataForm.value.longitude,sampleDataForm.value.latitude);
    })
}
// 编辑任务
function handleEdit2(id) {
    isView2.value = false;
    title2.value = "修改抽样点";
    detail2(id);
}
// 查看任务
function handleDetail2(id) {
    isView2.value = true;
    title2.value = "查看抽样点";
    detail2(id);
}
// 查看任务
function detail2(id) {
    getDetail2({ id: id }).then(res => {
        open2.value = true;
        proxy.resetForm("addRef2");
        form2.value = res.data;
        if (title.value == '修改抽样点') {
          if(res.data.id==sampleDataForm.value.id){
            //抽样点经纬度
            form2.value.longitude = sampleDataForm.value.longitude;
            form2.value.latitude = sampleDataForm.value.latitude;
            form2.value.geom = sampleDataForm.value.geom;
          }
        }
    })
}
// 保存抽样点
function save2() {
    proxy.$refs["addRef2"].validate(valid => {
        if (valid) {
            let lon = form2.value.longitude;
            let lat = form2.value.latitude;
            form2.value.geom = "POINT("+ lon + " " + lat + ")";//空间数据
            form2.value.type = "0";//type 0:新建的评估子区   1:重新划定的评估子区
            if (title2.value == '新建抽样点') {
                saveData2({ ...form2.value }).then(res => {
                    proxy.$modal.msgSuccess("新建成功");
                    open2.value = false;
                    getList2();
                    getAllDataList2();//获取全部抽样点列表
                })

              clearSelectFeatureBool.value = true;//是否删除选中要素
            } else if (title2.value == '修改抽样点') {
                updateData2({ ...form2.value }).then(res => {
                    proxy.$modal.msgSuccess("保存成功");
                    open2.value = false;
                    getList2();
                    getAllDataList2();//获取全部抽样点列表
                })
            }
        }
    })
}
//根据经纬度获取地址
function getLonLatAddress(lon,lat){
  if(lon!=null && lat!=null && lon>=-180 && lon<=180 && lat>=-90 && lat<=90){}else{
    proxy.$modal.msgWarning("经纬度错误");
    return;
  }
  //设置url
  let url = "https://fxpc.mem.gov.cn/data_preparation/171dd1d5-bbb3-483a-a7f6-50d6d98cee1f/b5c55956-d1d7-4c00-8ccc-3145269327e3/reverse_geocoding?location=" + lon + "," +lat + "&geokey=94E99EB4FEB9B48CD5348F7BCF5BB620";
  //天地图数据服务获取地址--逆地理编码查询
  let httpRequest = new XMLHttpRequest();//第一步：建立所需的对象
  httpRequest.open('GET', url, true);//第二步：打开连接  将请求参数写在url中  ps:"http://localhost:8080/rest/xxx"
  httpRequest.send();//第三步：发送请求  将请求参数写在URL中
  /**
   * 获取数据后的处理程序
   */
  httpRequest.onreadystatechange = function () {
    if (httpRequest.readyState == 4 && httpRequest.status == 200) {
      let json = httpRequest.responseText;//获取到json字符串，还需解析
      let obj = JSON.parse(json);
      //let addressComponent = obj.result.addressComponent;
      let addressComponent = obj.result.address_component;
      let code = addressComponent.adcode;
      let country = addressComponent.country;
      let province = addressComponent.province;
      let city = addressComponent.city;
      let area = addressComponent.district;
      let township = obj.result.formatted_address;
      if(obj.status=="0" && country=="中国"){
        //抽样点位置省、市、区县、详细地址
        form2.value.province = province;
        form2.value.city = city;
        form2.value.area = area;
        form2.value.address = township;
      }else{}
    }else if(httpRequest.readyState == 4 && httpRequest.status == 500){
      proxy.$modal.msgWarning("经纬度未查到详细地址");
    }
  };
}
function openTask() {
    isView.value = false;
    title.value = '新建任务';
    getInfo();
}

function getInfo() {
    // getTaskCreateInfo({eventCode:currentEvent.value.eventCode}).then(res => {
    //     open.value = true;
    //     proxy.resetForm("addRef");
    //     form.value = res.data;
    //     //任务范围
    //     form.value.evaluationSubareaRange = taskDataForm.value.geom;
    //     form.value.geom = taskDataForm.value.geom;//空间数据
    // })
    getCode().then(res => {
        open.value = true;
        proxy.resetForm("addRef");
        form.value = res.data;
        //任务范围
        form.value.taskRange = taskDataForm.value.geom;
        form.value.geom = taskDataForm.value.geom;//空间数据
    })
}
function selectGroup() {
    if (!isView.value) {
        queryParams1.value = {
            page: 1,
            rows: 10,
        };
        getList1();
    }
}
// 修改任务
function handleEdit(xstmId) {
    isView.value = false;
    title.value = "修改任务";
    detail(xstmId);
}
// 查看任务
function handleDetail(xstmId) {
    isView.value = false;
    title.value = "查看任务";
    detail(xstmId);
}
const positonGeom = ref('')
function handleDetailPosition(xstmId) {
  findById({ id: xstmId }).then(res => {
    positonGeom.value = res.data.geom
    form.value = res.data;
  })
}
function clearPosition() {
  positonGeom.value = ''
}
// 查看任务
function detail(id) {
    findById({ id: id }).then(res => {
        open.value = true;
        proxy.resetForm("addRef");
        form.value = res.data;
        if (title.value == '修改任务') {
          if(res.data.xstmId==taskDataForm.value.xstmId){
            //任务范围
            form.value.taskRange = taskDataForm.value.geom;
            form.value.geom = taskDataForm.value.geom;//空间数据
          }
        }
    })
}
const queryList = ref([])
function saveGeom(list) {
  queryList.value = []
  for(let i =0;i < list.length;i++) {
    let polygonWkt = "MULTIPOLYGON((";
    let coords = list[i].geometry.coordinates;
    for(let i = 0;i < coords.length;i++) {
      let polygon = "(";
      for(let j = 0;j < coords[i].length;j++) {
        if(j>0){
          polygon += ",";
        }
        let lonlat = coords[i][j];
        polygon += lonlat[0]+" "+lonlat[1];
      }
      if(i == coords.length - 1) {
        polygonWkt += polygon + ')))'
      }else{
        polygonWkt += polygon + '),'
      }
    }
    let params = {
      xsemId: currentEvent.value.id,
      xsemCode: currentEvent.value.eventCode,
      taskName: '任务--' + geomList.value[i].teamName,
      taskRange: polygonWkt,
      groupId: geomList.value[i].xitId,
      groupName: geomList.value[i].teamName,
      geom: polygonWkt,
      groupNumber: list.length,
      taskType: '0',
      quadrantNumber: i + 1
    }
    queryList.value.push(params)
  }
  accTotheGroupSave(queryList.value).then(res => {
    getAllDataList()
    getList()
    proxy.$modal.msgSuccess('创建成功')
    proxy.$modal.closeLoading();
  }).catch(error => {
    proxy.$modal.closeLoading();
  })
}
// 保存任务
function save() {
    // form.value.evaluationSubareaRange = '北京市西城区银岛大厦';
    proxy.$refs["addRef"].validate(valid => {
        if (valid) {
            if (title.value == '新建任务') {
              let objeceData = liduJiBieData.value.find(item => item.intensity1 == layerName.value)
                //type 0:新建的评估子区   1:重新划定的评估子区
                savePolygon({ ...form.value,taskType: '1', xsemId: currentEvent.value.id,xsemCode:currentEvent.value.eventCode }).then(res => {
                    proxy.$modal.msgSuccess("新建成功");
                    open.value = false;
                    getList();
                    layerTypeMap.value = { name: 'change'} 
                    getSeismicInfluenceArray();
                    getAllDataList();//获取全部任务列表
                })

                clearSelectFeatureBool.value = true;//是否删除选中要素
            } else if (title.value == '修改任务' || title.value == '查看任务') {
                updatePolygon({ ...form.value }).then(res => {
                    proxy.$modal.msgSuccess("保存成功");
                    open.value = false;
                    getList();
                    getAllDataList();//获取全部任务列表
                })

                //是否为地图右键菜单新建任务|修改任务
                if(form.value.xstmId==taskDataForm.value.xstmId){
                  clearSelectFeatureBool.value = true;//是否删除选中要素
                }
            }
        }
    })
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
    multiple.value = !selection.length;
    groupId.value = selection.map((item) => item.xitId);
    groupName.value = selection.map((item) => item.teamName);
};
const deleteListData = ref([])
function handleSelectionChangeDelete(selection) {
  deleteListData.value = selection
}
function deleteTaskList() {
  let idList = ''
  for(let i = 0;i < deleteListData.value.length;i++) {
    if(idList == '') {
      idList += deleteListData.value[i].xitmId
    }else{
      idList += ','+ deleteListData.value[i].xitmId
    }
  }
  handleDelete(idList)
  deleteTask.value = false
}

function queryGroup() {
    form.value.groupName = groupName.value.join(',');
    form.value.groupId = groupId.value.join(',');
    open1.value = false;
}
/** 删除按钮操作 */
function handleDelete(xstmId) {
    proxy.$modal
        .confirm("请确认是否要删除该任务？",)
        .then(function () {
            return deletePolygon(xstmId);
        })
        .then(() => {
            getList();
            getAllDataList();//获取全部任务列表
            proxy.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
}
/** 删除按钮操作 */
function handleDelete2(id) {
  proxy.$modal
      .confirm("请确认是否要删除选中该抽样点？",)
      .then(function () {
        return del2(id);
      })
      .then(() => {
        getList2();
        getAllDataList2();//获取全部抽样点列表
        proxy.$modal.msgSuccess("删除成功");
      })
      .catch(() => { });
}
/** 查询数据列表--获取任务列表（分页） */
function getList() {
    if (currentEvent.value) {
        loading.value = true;
        //0:新建的评估子区   1:重新划定的评估子区
        getPageTask({ ...queryParams.value, xsemId: currentEvent.value.id },"0").then(response => {
            dataList.value = response.data.rows ? response.data.rows : [];
            total.value = response.data.total;
            loading.value = false;
        });
    } else {
        dataList.value = [];
        total.value = 0;
    }
}
/** 查询数据列表--获取全部任务列表 */
function getAllDataList() {
  if (currentEvent.value) {
    loading.value = true;
    //0:新建的评估子区   1:重新划定的评估子区
    getTaskList({xsemId: currentEvent.value.id,taskType: ''}).then(response => {
      allDataList.value = response.data;
      loading.value = false;
    });
  } else {
    allDataList.value = [];
  }
}
/** 查询数据列表--获取小组列表 */
function getList1() {
    if (currentEvent.value) {
        getAllList1({ ...queryParams1.value, xsemId: currentEvent.value.id }).then(response => {
            dataList1.value = response.data.rows ? response.data.rows : [];
            total1.value = response.data.total;
            open1.value = true;
        });
    } else {
        dataList1.value = [];
        total1.value = 0;
    }
}
/** 查询数据列表--获取抽样点列表（分页） */
function getList2() {
    if (currentEvent.value) {
        loading2.value = true;
        //type 0:新建的评估子区   1:重新划定的评估子区
        getAllList2({ ...queryParams2.value, xsemId: currentEvent.value.id }).then(response => {
            dataList2.value = response.data.rows ? response.data.rows : [];
            total2.value = response.data.total;
            loading2.value = false;
        });
    } else {
        dataList2.value = [];
        total2.value = 0;
    }
}
/** 查询数据列表--获取全部抽样点列表 */
function getAllDataList2() {
  if (currentEvent.value) {
    loading2.value = true;
    //type 0:新建的评估子区   1:重新划定的评估子区
    getAllSamPoiDataList({ ...queryParams2.value, xsemId: currentEvent.value.id,type:"0" }).then(response => {
      allDataList2.value = response.data;
      loading2.value = false;
    });
  } else {
    allDataList2.value = [];
  }
}
// 查看调查组
function detail1(id) {
    getDetail1({ id: id }).then(res => {
        openGroup.value = true;
        proxy.resetForm("groupRef");
        activeName.value = 'first'
        formGroup.value = res.data;
    })
}
/*地图传参start*/
const pageType = ref("调查任务管理页面");
const mapLoading = ref(false);
const completeRefreshData = ref(false);//防止刷新后地图不显示
//地图对象
const map = ref(null);
const getMap = (obj)=>{
  map.value = obj;
}
const outAndInterRingData = ref([])
const outAndInterRing = (list) => {
  outAndInterRingData.value = list
}
const closePingGu = () => {
  layerType.value = ''
  layerTypeMap.value = {name: ''} 
}
const mapDrawType = ref("");//是否开启地图圈选查询类型（StopDraw关闭地图圈选 Polygon多边形绘制 Circle圆形绘制 Clear清空）
const polygonDrawBool = ref(false);
//全部地图绘制空间数据
const allDrawGeomText = ref("");
//获取全部地图绘制结果
const getAllDrawGeom = (list) =>{
  let geom = "";
  if(list && list.length>0){
    geom = "MULTIPOLYGON(";
    for(let i=0;i<list.length;i++){
      if(i>0){
        geom += ",";
      }
      geom += list[i].split("POLYGON")[1];
    }
    geom += ")";
  }
  if(geom=="MULTIPOLYGON()"){
    geom = "";
  }
  allDrawGeomText.value = geom;//全部地图绘制空间数据
}
const showFsiSelectBool = ref(false);//是否显示选择快速影响场
//选择地震影响场
const seismicInfluenceSelect = (val)=>{
  showFsiSelectBool.value = val;
  if(val){
    showFastSiVersionTableBool.value = true;
    // 根据事件ID查询地震影响场版本信息列表
    getFastSiVersionList();
  }else{
    showFastSiVersionTableBool.value = false;
    fastSeismicInfluenceList.value = [];
  }
}
const layerSelectViable = ref(false)
const createDraew = ref(false)
const geomList = ref([])
const newTaskBool = ref(true)
const closeNewTask = () => {
  newTaskBool.value = true
}
//开启烈度选择框
const openLayerSelect = (val) => {
  debugger
  // layerSelectViable.value = val
  if(createTaskType.value == '2') {
    // createDraew.value = val
    mapDrawType.value = 'Polygon'
  }else{
    createDraew.value = false
    getInvGroupListByXsemId({xsemId: currentEvent.value.id}).then(res => {
      if(res.data.length == 0) {
        proxy.$modal.confirm("请添加调查小组",).then(function () {
          return;
        })
        .then(() => {
          
        })
        .catch(() => { });
      }else{
        proxy.$modal.confirm("确认按小组个数平均分配并自动创建任务吗?",).then(function () {
          return;
        }).then(() => {
          getTaskList({xsemId: currentEvent.value.id,taskType: '0'}).then(response => {
            allDataList.value = response.data;
            if(response.data.length == 0) {
              proxy.$modal.loading('正在创建任务.....')
              geomList.value = res.data
            }else{
              proxy.$modal.confirm("重新新建并分配会清空现有任务，是否继续?",).then(function () {
                deleteByXsemId(currentEvent.value.id).then(resdata => {
                  proxy.$modal.msgSuccess('删除成功')
                  proxy.$modal.loading('正在创建任务.....')
                })
                return;
              }).then(() => {
                geomList.value = res.data
              }).catch(() => {
                newTaskBool.value = false
              });
            }
          });
        }).catch(() => { newTaskBool.value = false});
      }
    })
  }
  if(val == false) {
    mapDrawType.value = ''
    // layerType.value = ''
    // layerTypeMap.value = {name: ''} 
    // layerTypeVisable.value = false
    // layerName.value = ''
    // drawGeom.value = ''
  }
}
const clearSelectFeatureBool = ref(false);//是否删除选中要素
const taskTableData = ref([])
//新建任务|修改任务
const createTaskArea = (obj)=>{
  clearSelectFeatureBool.value = false;//是否删除选中要素
  let xstmId = obj.xstmId;
  taskDataForm.value.xstmId = xstmId;
  if(obj.type=="保存"){
    if(obj.geom){
      taskDataForm.value.geom = obj.geom;
      //根据事件ID、空间数据查询灾区范围列表
      getSeismicInfluenceArray(obj.geom);
    }else{
      taskDataForm.value.geom = "";
    }
  }else if(obj.type=="查看"){
    if(xstmId){
      // 查看任务
      handleDetail(xstmId);
    }
  }else if(obj.type=="删除"){
    if(xstmId){
      if(obj.list.length == 1) {
        // 删除任务
       handleDelete(xstmId);
      }else{
        taskTableData.value = obj.list
        deleteTask.value = true
      }
    }
  }
}
//新建抽样点
const createSamplePoint = (obj)=>{
  clearSelectFeatureBool.value = false;//是否删除选中要素
  let id = obj.id;
  sampleDataForm.value.id = id;
  if(obj.type=="保存"){
    if(obj.lon && obj.lat){
      sampleDataForm.value.longitude = obj.lon;
      sampleDataForm.value.latitude = obj.lat;
      let geom = "POINT("+ obj.lon + " " + obj.lat + ")";//空间数据
      sampleDataForm.value.geom = geom;
      if(obj.taskType == '任务点' && id == '') {
        //根据事件ID、空间数据查询任务列表
        getSurTaskManageArray(geom);
      }else if(obj.taskType == '象限点'){
        sampleDataForm.value.xitmId = obj.PolygonID;//任务id
        openPoint();
      }else if(id != '') {
        handleEdit2(id)
      }
    }else{
      sampleDataForm.value.longitude = "";
      sampleDataForm.value.latitude = "";
      sampleDataForm.value.geom = "";
    }
  }else if(obj.type=="查看"){
    if(id){
      // 查看抽样点
      handleDetail2(id);
    }
  }else if(obj.type=="删除"){
    if(id){
      // 删除抽样点
      handleDelete2(id);
    }
  }
}
//类型zqfw,事件ID
const typeCode = ref("");
//根据事件ID查询灾区范围列表
function getSeismicInfluenceArray(geom){
  let fvId = selectFastSiVersion.value.fvId;
  if (fvId) {
    //
  }else{
    return;
  }
  if (currentEvent.value) {
    let xsemId = currentEvent.value.id;
    //类型zqfw,事件ID
    typeCode.value = "zqfw,"+xsemId;
    getFastSeiInfAndVerListByFvId(fvId,geom).then(response => {
      let list = response.data;
      if(geom){//新建|修改任务前查询空间范围是否在灾区范围内
        //新建任务
        openTask();
      }else{//初始化查询灾区范围
        fastSeismicInfluenceList.value = list;
        liduJiBieData.value = list
        if(list && list.length>0){
          let legendList = shpLegendList.value;
          for(let i=0;i<legendList.length;i++){
            let val = legendList[i].value;
            for(let j=0;j<list.length;j++){
              if(val==list[j].intensity){//烈度
                legendList[i].show = true;//只显示灾区范围的烈度
                break;
              }
            }
          }
          shpLegendList.value = legendList;
        }
      }
    });
  }else{
    fastSeismicInfluenceList.value = [];
  }
}
//根据事件ID、空间数据查询任务列表
function getSurTaskManageArray(geom){
  if (currentEvent.value && geom) {
    let xsemId = currentEvent.value.id;
    getInvTaskManageList(xsemId,geom).then(response => {
      let list = []
      if(response.data.length > 0) {
        let num1 = response.data[0].createTime
        let dataList = response.data[0]
        for(let i = 1;i < response.data.length;i++) {
          if(num1 < response.data[i].createTime) {
            num1 = response.data[i].createTime
            dataList = response.data[i]
          }
        }
        list = [dataList];
      }else{
        list = response.data
      }
      //新建|修改抽样点前查询抽样点是否在1个任务区域内
      if(list && list.length>0){
        if(list.length==1){//符合抽样点应在1个任务区域内
          let xitmId = list[0].xitmId;//任务ID
          sampleDataForm.value.xitmId = xitmId;//任务id
          let id = sampleDataForm.value.id;//抽样点ID
          if(id){
            //修改抽样点
            handleEdit2(id);
          }else{
            //新建抽样点
            openPoint();
          }
        }else{
          proxy.$modal.msgWarning("抽样点应在1个任务区域内，请修改抽样点");
        }
      }else{
        proxy.$modal.msgWarning("抽样点应在1个任务区域内，请修改抽样点");
      }
    });
  }
}
/*地图传参end*/
const total3 = ref(0);
const showFastSiVersionTableBool = ref(false);//是否显示快速生成影响场版本选择面板
const tableLoading = ref(false);
const fastSiVersionList = ref([]);
//选择快速影响场版本
const selectionData = ref({});
const selectRadio = ref('');
//单选选择
function getCurrentRow(row) {
  if (selectRadio.value) {
    if (selectRadio.value == row.fvId) {
      selectRadio.value = ''
      selectionData.value = {};// 取消勾选就把回传数据清除
      return;
    }
  }
  selectRadio.value = row.fvId;
  selectionData.value = row;
}
//确定选择快速影响场版本
const submitVersionSelect = ()=>{
  if (selectRadio.value) {
    showFastSiVersionTableBool.value = false;
    showFsiSelectBool.value = false;
    // 调查任务管理--根据类型查询事件的全部新建的评估子区数量
    countSurTaskManage();
  }else{
    fastSeismicInfluenceList.value = [];
    showFsiSelectBool.value = false;
    proxy.$modal.msgWarning("请选取版本");
  }
}
//关闭选择快速影响场版本
const closeVersionSelectDialog = () =>{
  showFastSiVersionTableBool.value = false;
  showFsiSelectBool.value = false;
}
// 根据事件ID查询地震影响场版本信息列表
function getFastSiVersionList(){
  let xsemId = currentEvent.value.id;
  if(xsemId){
    tableLoading.value = true;
    getFastSiVersionListByXsemId({xsemId,...queryParams3.value}).then(res=>{
      fastSiVersionList.value = res.data.rows ? res.data.rows : [];
      total3.value = res.data.total;
      tableLoading.value = false;
    })
  }
}
//地震影响场空间数据列表
const fastSeismicInfluenceList = ref([]);
// 根据版本ID查询地震影响场空间数据列表
function getFastSeismicInfluenceList(fvId){
  getFastSeiInfAndVerListByFvId(fvId,"").then(res=>{
    let data = res.data;
    fastSeismicInfluenceList.value = data;
  })
}
//事件ID选择的地震影响场版本信息
const selectFastSiVersion = ref({});
// 调查任务管理--根据事件ID查询选择的地震影响场版本信息
function getSelectFastSiVersionByXsemId(xsemId){
  getFastSiVersionByXsemId(xsemId).then(res=>{
    let data = res.data;
    if(data){
      selectFastSiVersion.value = data;
      //确定选择
      getCurrentRow(data);
      //根据事件ID查询灾区范围列表
      getSeismicInfluenceArray("");
    }
  })
}
// 调查任务管理--根据事件ID设置全部快速生成地震影响场版本信息未选择、删除全部新建的评估子区
function setUnselectFastSiVersionDeleteTask(xsemId,fvId){
  setUnselectFastSiVersionDeleteTaskByXsemId(xsemId,fvId).then(res=>{ })
}
// 调查任务管理--根据类型查询事件的全部新建的评估子区数量
function countSurTaskManage(){
  if(selectFastSiVersion.value && currentEvent.value){
    let fvId = selectFastSiVersion.value.fvId;
    let xsemId = currentEvent.value.id;
    // 调查任务管理--根据类型查询事件的全部新建的评估子区数量
    countSurTaskManageByType({xsemId: xsemId,type: "0"}).then(res=>{
      let count = res.data;
      if(count>0){
        proxy.$modal.confirm("地震事件下加载的影响场已经存在评估子区，删除任务评估子区后才能重新加载影响场，是否确定删除任务评估子区？").then(function() {
          // 调查任务管理--根据事件ID设置全部快速生成地震影响场版本信息未选择、删除全部新建的评估子区
          return setUnselectFastSiVersionDeleteTask(xsemId,fvId);
        }).then(() => {
          // 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
          setSelectFastSiVersionByFvId(xsemId);
          proxy.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      }else{
        // 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
        setSelectFastSiVersionByFvId(xsemId);
      }
    });
  }
}
// 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
function setSelectFastSiVersionByFvId(xsemId){
  let fvId = selectRadio.value;
  if(fvId){
    selectFastSiVersion.value = selectionData.value;
    // 调查任务管理--事件的1个快速生成地震影响场版本信息设置选择
    setSelectFastSiVersion(xsemId,fvId).then(res=>{
      // 根据版本ID查询地震影响场空间数据列表
      // getFastSeismicInfluenceList(fvId);
      initFunction();//初始化
    })
  }
}
//初始化
function initFunction(){
  if(completeRefreshData.value && currentEvent.value){
    getAllDataList();//获取全部任务列表
    getAllDataList2();//获取全部抽样点列表
    getList();//获取任务列表（分页）
    getList2();//获取抽样点列表（分页）
    getTreeselect();
    let xsemId = currentEvent.value.id;
    if(xsemId){
      // 调查任务管理--根据事件ID查询选择的地震影响场版本信息
      getSelectFastSiVersionByXsemId(xsemId);
    }
  }
}
const optionsSelect = ref([]);
//查询行政区划树列表
const districtTreeList = ref([]);
function getTreeselect() {
  getAreaTree().then((response) => {
    nextTick(() => {
      optionsSelect.value = disposeata(JSON.parse(response.data));
      //地图行政区划列表
      districtTreeList.value = optionsSelect.value;
    });
  });
}
function disposeata(data) {
  data.forEach((item) => {
    item.label = item.name;
    item.key = item.id;
    item.children && disposeata(item.children);
  });
  return data;
}
//获取当前事件
watch(() => currentEvent.value, val => {
  if(val && val.id){
    initFunction();//初始化
  }
},{ deep: true, immediate: true });

onMounted(() => {
  completeRefreshData.value = true;
  initFunction();//初始化
})
</script>
  
<style scoped lang="scss">
.title {
    margin: 0 0 20px !important;
}

.mapDiv {
  position:absolute;top:0px;left:0px;width:100%;height:100%;
}

.currentEventDiv {
  position:absolute;top:20px;right:20px;height:100px;background:rgba(255,255,255,0.8);border:1px solid gray;padding:10px;
}
.liduJiBie {
  position: absolute;
  top: 80px;
  left: 100px;
  background: #fff;
  box-shadow: 0px 0px 20px rgb(0 0 0 / 20%);
  border: 1px solid #707070;
  border-radius: 4px;
  padding: 5px;
  z-index: 10;
}
/*灾区范围图层图例*/
.new-legendDiv {
  position: absolute;
  bottom: 0px;
  right: 0px;
  background: #fff;
  box-shadow: 0px 0px 20px rgb(0 0 0 / 20%);
  border: 1px solid #707070;
  border-radius: 4px;
  padding: 5px;
}
.new-legendDiv div {
  position: relative;
  height: 16px;
  line-height: 16px;
  font-size: 13px;
  margin: 8px;
}
.new-legendDiv div span {
  line-height: 16px;
  font-size: 13px;
}
.new-legendDiv div div {
  position: relative;
  top: 2px;
  left: 8px;
  width: 30px;
  height: 14px;
  margin: 0px !important;
  margin-right: 25px !important;
  display: inline-block;
}
.new-legendDiv-polygon {
  position: relative !important;
  left: 0px !important;
  top: 0px !important;
  border:1px solid black;
  background:#fff;
}
</style>
  
  